package com.example.orchid.coordinatorlayoutdemo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;

/**
 * Activity基础类
 * Created by Orchid on 2015-10-21.
 */
public abstract class BaseActivity extends AppCompatActivity {


    /**
     * 加载布局
     *
     * @return
     */
    protected abstract int getContentView();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentView());
        initView();
    }

    /**
     * 初始化view
     */
    protected abstract void initView();

    /**
     * 查找view
     *
     * @param id  资源id
     * @param <T> 类型
     * @return 资源id对应的视图
     */
    protected <T extends View> T findView(int id) {
        return (T) findViewById(id);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

}
